#include "stdafx.h"
//---------------------------------------------------------------------
//                  The CBaseClassFactory implementation
//---------------------------------------------------------------------

STDMETHODIMP
CBaseClassFactory::QueryInterface(REFIID riid, void** ppvObj)
{
    switch (riid.Data1)
    {
        case 0: //IUnknown
        case 1: //IClassFactory
            if (IIDOK(IUnknown) || IIDOK(IClassFactory))
            {
                *ppvObj = this;
                m_dwRefs++;
                return NOERROR;
                break;
            }
            // Fall Through
        default:
            *ppvObj = NULL;
            return E_NOINTERFACE;
    }
}

STDMETHODIMP        
CBaseClassFactory::CreateInstance(IUnknown FAR* pUnkOuter, REFIID riid, void FAR* FAR* ppv)
{
    IUnknown FAR *pcdt = NULL;
    HRESULT hr;

    //No aggregation
    if (pUnkOuter)
    {
        return CLASS_E_NOAGGREGATION;
    }
    else if (!IIDOK(IUnknown) && (m_pIID && !IsEqualIID(riid, *m_pIID)))
    {
        return E_NOINTERFACE;
    }
      
    if FAILED(hr = Create(&pcdt))
    {
        *ppv = NULL;
        return hr;
    }
    else if(pcdt == NULL)
    {
        *ppv = NULL;
        return E_FAIL;
    }
    hr = pcdt->QueryInterface(riid, ppv);
    pcdt->Release();
    return hr;
}
